//
//  CodeViewController.m
//  JiaoWuGuanLi
//
//  Created by Zinzie on 14-2-20.
//  Copyright (c) 2014年 Zinzie. All rights reserved.
//

#import "CodeViewController.h"
#import "TFHpple.h"

@interface CodeViewController ()

@end

@implementation CodeViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
//	self.backGround.text = nil;
    
    AFHTTPRequestOperationManager *manager2 = [AFHTTPRequestOperationManager manager];
    
    manager2.responseSerializer = [AFHTTPResponseSerializer serializer];
    //     manager2.responseSerializer.stringEncoding=enc;
    manager2.requestSerializer = [AFHTTPRequestSerializer serializer];
    //     manager2.requestSerializer.stringEncoding = enc;
    //
    
    //          NSDictionary *parameters2 = @{@"xh":@"11024132",@"xm":@"张全鹏",@"gnmkdm":@"N121603"};
    [manager2 GET:@"http://172.21.96.64/xscjcx.aspx?xh=11024132&xm=%D5%C5%C8%AB%C5%F4&gnmkdm=N121605" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
//              NSLog(@"huoqushuju: %ld",(long)operation.response.statusCode);
              NSLog(@"数据：%@",operation.responseString);
              self.backGround.text=operation.responseString;
//              NSData *data=[operation.responseString dataUsingEncoding:NSUTF8StringEncoding];
//              NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:data];
              // 代理
//              xmlParser.delegate =self;
              //解析
//              // 开始解析
//              BOOL flag = [xmlParser parse];
//              if (flag) {
//                  NSLog(@"解析成功");
//              }
//              else{
//                  NSLog(@"解析出错");
//              }
              
              NSString *utf8HtmlStr = [operation.responseString stringByReplacingOccurrencesOfString:@"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">" withString:@"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">"];
              NSData *htmlDataUTF8 = [utf8HtmlStr dataUsingEncoding:NSUTF8StringEncoding];
              TFHpple *xpathParser = [[TFHpple alloc]initWithHTMLData:htmlDataUTF8];
              NSArray *elements  = [xpathParser searchWithXPathQuery:@"//table[@class='datelist']"];
              
              // Access the first cell
              TFHppleElement *element = [elements objectAtIndex:0];
              
              // Get the text within the cell tag
              NSString *content = [element text];
              NSString *ta=[element tagName];
              NSString *view=[element objectForKey:@"value"];
              NSLog(@"学号姓名为%@%@%@",content,ta,view);
              
              
          } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
              NSLog(@"Error: %@", [error debugDescription]);
          }];//获取登陆后的网页

    
    // Do any additional setup after loading the view.
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
